class Solution
{
public:
    int maxPoints(vector<vector<int>> &points)
    {
        set<vector<long long>> visitedLines;
        int n = points.size();
        if (n <= 2)
        {
            return n;
        }
        int result = 2;
        for (int i = 0; i < n; ++i)
        {
            for (int j = i + 1; j < n; ++j)
            {
                auto line = getLine(points[i], points[j]);
                if (!visitedLines.count(line))
                {
                    int pointInLineCount = 0;
                    for (auto &p : points)
                    {
                        if (pointInLine(p, line))
                        {
                            ++pointInLineCount;
                        }
                    }
                    visitedLines.insert(line);
                    result = max(result, pointInLineCount);
                }
            }
        }
        return result;
    }

    vector<long long> getLine(vector<int> &p1, vector<int> &p2)
    {
        // 将直线表示成 Ay + Bx + C = 0 的形式，其中 ABC 都是整数
        return {p2[0] - p1[0], p1[1] - p2[1], p1[0] * p2[1] - p1[1] * p2[0]}; // {A, B, C}
    }

    bool pointInLine(vector<int> &p, vector<long long> &l)
    {
        return l[0] * p[1] + l[1] * p[0] + l[2] == 0;
    }
};